# include <bits/stdc++.h>

const int32_t maxn = 400005;

const int32_t logn = 50;

const int64_t lim = 1e12;

int32_t n;

int64_t x, sum = 0;

std::unordered_set <int64_t> s;

std::vector <int64_t> v;

namespace segtree {
	
	struct node {
		int32_t ls, rs;
		int64_t siz, sum, pre, suf;
	} t[maxn * logn];
	
	# define lc (t[x].ls)
	# define rc (t[x].rs)
	# define m ((l + r) >> 1)
	
	int32_t tot = 1, rt = 1;
	
	inline void maintain (const int32_t x) {
		t[x].pre = t[lc].pre + t[rc].pre + t[lc].sum * t[rc].siz;
		t[x].suf = t[lc].suf + t[rc].suf + t[rc].sum * t[lc].siz;
		t[x].sum = t[lc].sum + t[rc].sum;
		t[x].siz = t[lc].siz + t[rc].siz;
	}
	
	inline void ins (const int64_t p, const int64_t l = 1, const int64_t r = lim, int32_t & x = rt) {
		if (! x) x = ++ tot;
		if (l == r) return t[x] = {0, 0, 1, p, p, p}, void ();
		p <= m ? ins (p, l, m, lc) : ins (p, m + 1, r, rc); maintain (x);
	}
	
	inline void del (const int64_t p, const int64_t l = 1, const int64_t r = lim, const int32_t x = 1) {
		if (l == r) return t[x] = {0, 0, 0, 0, 0, 0}, void ();
		p <= m ? del (p, l, m, lc) : del (p, m + 1, r, rc); maintain (x);
	}
	
	inline int64_t pres (const int32_t s, const int64_t l = 1, const int64_t r = lim, const int32_t x = 1) {
		if (t[lc].siz == s) return t[lc].sum;
		
		if (t[lc].siz >  s) return pres (s, l, m, lc);
		if (t[lc].siz <  s) return pres (s - t[lc].siz, m + 1, r, rc) + t[lc].sum;
		
		return 0;
	}
	
	inline int64_t sufs (const int32_t s, const int64_t l = 1, const int64_t r = lim, const int32_t x = 1) {
		if (t[rc].siz == s) return t[rc].sum;
		
		if (t[rc].siz >  s) return sufs (s, m + 1, r, rc);
		if (t[rc].siz <  s) return sufs (s - t[rc].siz, l, m, lc) + t[rc].sum;
	
		return 0;
	}
	
	inline int64_t qpre (const int32_t s, const int64_t l = 1, const int64_t r = lim, const int64_t x = 1) {
		
		if (t[lc].siz == s) return t[lc].pre;
		
		if (t[lc].siz >  s) return qpre (s, l, m, lc);
		
		return t[lc].pre + qpre (s - t[lc].siz, m + 1, r, rc) + t[lc].sum * (s - t[lc].siz);
	}
	
	inline int64_t qsuf (const int32_t s, const int64_t l = 1, const int64_t r = lim, const int64_t x = 1) {
		
		if (t[rc].siz == s) return t[rc].suf;
		
		if (t[rc].siz >  s) return qsuf (s, m + 1, r, rc);
		
		return t[rc].suf + qsuf (s - t[rc].siz, l, m, lc) + t[rc].sum * (s - t[rc].siz);
		
	}
	 
}

std::unordered_map <int64_t, int32_t> mp;

int main () {
	
	freopen ("kte.in", "r", stdin);
	freopen ("kte.out", "w", stdout);
	
	std::ios::sync_with_stdio (0);
	std::cin.tie (0), std::cout.tie (0);
	
	std::cin >> n;
	
	for (int i = 1; i <= n; ++ i) {
		
		std::cin >> x;
		
		if (mp.count (x)) 
			mp.erase (mp.find (x)), sum -= x, segtree::del (x);
		else
			mp[x] = 1, sum += x, segtree::ins (x);
		
		if (mp.size () <= 1) {
			std::cout << 0 << '\n';
			continue ;
		}
	
		int64_t s = mp.size (), l = 1, r = s / 2, res1 = l, res2 = s;
		
		if (segtree::pres (2) <= segtree::sufs (1))
			res1 = 1, r = l - 1;
			
		while (l <= r) {
			
			if (segtree::pres (m) > segtree::sufs (m - 1))
				res1 = m, l = m + 1;
			else
				r = m - 1;
				
		}
		
		l = s / 2, r = s, res2 = s;
		
		while (l <= r) {
			
			if (segtree::pres (m) > segtree::sufs (m - 1))
				res2 = m, r = m - 1;
			else
				l = m + 1;
				
		}
		
		int64_t ans = 0;
		
		ans = ans + segtree::qsuf (res1 - 1) - segtree::qpre (res1 - 1);
		
		ans = ans + segtree::qsuf (mp.size () - 1) - segtree::qsuf (res2 - 1) - (segtree::qpre (mp.size () - 1) - segtree::qpre (res2 - 1));
		
		if (res2 > res1)	
			ans = ans + segtree::sufs (res2 - 1) - segtree::pres (res1);
		
		std::cout << ans << '\n';
		
	}
	
	return 0;
}